import { config } from '../config.js'

class HTTP {
  request(url, data = {}, method = 'GET') {
    return new Promise((resolve, rejeect) => {
      wx.request({
        url: config.api_base_url + url,
        method,
        data,
        header: {
          'content-type': 'application/json'
        },
        success: (res) => {
          if(res.data.code === 20000) {
            resolve(res.data.data)
          } else {
            wx.showToast({
              title: res.data.msg,
              icon:'none',
              duration:2000
            }) 
          }
        },
        fail:(err)=>{
          rejeect(err)
        }
      })
    })

  }
}

export default HTTP